﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SmartSpace.UI.Silverlight.Dynamic.DynamicRef;
using System.Json;

namespace SmartSpace.UI.Silverlight.Dynamic.Windows
{
    public partial class SelectOrgWindow : ChildWindow
    {
        public Guid WorkflowId { get; private set; }
        public Guid ActivityId { get; private set; }
        public WorkflowEvent WorkflowEvent { get; private set; }
        public List<Guid> ReceiverIdList { get; private set; }

        public SelectOrgWindow(Guid workflowId, Guid activityId, WorkflowEvent workflowEvent)
        {
            InitializeComponent();

            WorkflowId = workflowId;
            ActivityId = activityId;
            WorkflowEvent = workflowEvent;
            ReceiverIdList = new List<Guid>();

            this.Loaded += new RoutedEventHandler(SelectReceiverWindow_Loaded);
        }

        private void SelectReceiverWindow_Loaded(object sender, RoutedEventArgs e)
        {
            DynamicWebServiceSoapClient client = DynamicModule.CreateProxy();
            client.GetCompleted += new EventHandler<GetCompletedEventArgs>(client_GetCompleted);
            client.GetAsync("0-1-1", string.Empty);
        }

        private void client_GetCompleted(object sender, GetCompletedEventArgs e)
        {
            if (e.Error == null && e.Result.IsSuccess)
            {
                JsonArray json = (JsonArray)JsonObject.Parse(e.Result.Data);
                _ctlTreeOrg.ItemsSource = json;
            }
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            //if (_ctlListUser.SelectedItem == null)
            //{
            //    MessageBox.Show("必须选择一个用户!");
            //    return;
            //}
            //WorkflowUser user = _ctlListUser.SelectedItem as WorkflowUser;
            //ReceiverIdList.Add(user.Id);

            this.DialogResult = true;
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }
    }
}

